package hiho.ku._1038;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int w = in.nextInt();
		int[] f = new int[w + 1];
		for (int i = 0; i < n; i++) {
			int c = in.nextInt();
			int v = in.nextInt();
			for (int j = w; j >= c; j--)
				f[j] = Math.max(f[j], f[j - c] + v);
		}
		System.out.println(f[w]);
	}

}
